﻿
using Xejen.Hosting;
using Xejen.Logger;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;

namespace Xejen.Common.Winform.Test
{
    /// <summary>
    /// 表示适用于Winform的主机
    /// </summary>
    /// <creator>marc</creator>
    public class WinFormAppHost<TForm> : AppHostBase
        where TForm : Form
    {
        /// <inheritdoc cref="WinFormAppHost{TForm}"/>
        /// <param name="loggerManager"><inheritdoc/></param>
        public WinFormAppHost(ILoggerManager loggerManager) : base(loggerManager) { }

        /// <inheritdoc cref="WinFormAppHost{TForm}"/>
        /// <param name="args"><inheritdoc/></param>
        /// <param name="loggerManager"><inheritdoc/></param>
        public WinFormAppHost(string[] args, ILoggerManager loggerManager) : base(args, loggerManager) { }

        /// <inheritdoc cref="WinFormAppHost{TForm}"/>
        /// <param name="configuration"><inheritdoc/></param>
        /// <param name="loggerManager"><inheritdoc/></param>
        public WinFormAppHost(HostConfiguration configuration, ILoggerManager loggerManager) : base(configuration, loggerManager) { }

        /// <inheritdoc/>
        protected override void ConfigureJsonFiles(IConfigurationBuilder configuration)
        {
            base.ConfigureJsonFiles(configuration);
        }

        /// <inheritdoc/>
        protected override void ConfigureServices(IServiceCollection services)
        {

            services.AddSingleton<TForm>();
        }

        /// <inheritdoc/>
        public override void Run()
        {
            Logger.LogInformation($"应用程序初始化完成，开始运行……");

            Application.Run(ServiceProvider.GetRequiredService<TForm>());
        }
    }
}
